
use "$path\Intermediary Data\base_CIR", clear
merge 1:1 id using "$path\Intermediary Data\moments_alt.dta"
sum kurtosis , d
local min=2.5
local max=97.5
winsor2 kurtosis , replace  cuts(`min' `max') trim
replace kurto=. if kurto>9
sum kurtosis , d
keep if _m==3
drop _m
merge 1:1 id using "$path\Intermediary Data\moments_EG"
sum freq , d
local min=2.5
local max=97.5
winsor2 freq , replace  cuts(`min' `max') trim
sum freq , d
egen tot=sum(nobs)
keep if _m==3
drop _m



sum CIR_2 , d
local min=1
local max=99
winsor2 CIR_2 , replace  cuts(`min' `max') trim



gen ratio=kurtosis/freq
sum ratio, d
local min=1
local max=99
winsor2 ratio , replace  cuts(`min' `max') trim
replace freq=. if ratio==.
replace kurt=. if ratio==.

replace ratio=kurtosis/freq

drop if ratio==.

drop if CIR_2==.





sum nobs, d
save "$path\Intermediary Data\base_stat_CRI", replace



********************************************************************
use "$path\Intermediary Data\base_stat_CRI", clear

sort nobs
gen sum_obs=sum(nobs)


gen year=(nobs/261)
gen share_obs=1-sum_obs/13712161
egen sum1=sum(nobs) if year>=1
egen sum2=sum(nobs) if year>=2

egen sum3=sum(nobs) if year>=3
egen sum4=sum(nobs) if year>=4
egen sum5=sum(nobs) if year>=5
egen sum6=sum(nobs) if year>=6
egen sum7=sum(nobs) if year>=7
egen sum8=sum(nobs) if year>=8
egen sum9=sum(nobs) if year>=9
egen sum10=sum(nobs) if year>=10

sum sum* tot

keep if year>=6
save "$path\Intermediary Data\base_stat_CRI6", replace 

***************************************


use "$path\Intermediary Data\base_stat_CRI6", clear 


binscatter CIR_2 ratio , nquantiles(100) ms(Oh)  mcolor(black) lcolor(black) ///
graphregion(color(white)) xtitle("Kurt/Freq") ytitle("CIR ") name(scatter1, replace) 
graph export "$path\Graphs_Tables\Figure5.png", replace
graph export "$path\Graphs_Tables\Figure5.eps", replace


binscatter CIR_2 freq , nquantiles(100) ms(Th)  mcolor(black) lcolor(black) ///
graphregion(color(white)) xtitle("Freq") ytitle("CIR ") ylabel(24(1)27)
graph export "$path\Graphs_Tables\Figure6_a.png", replace
graph export "$path\Graphs_Tables\Figure6_a.eps", replace


binscatter CIR_2 kurto , nquantiles(100) ms(Sh)  mcolor(black) lcolor(black) ///
graphregion(color(white)) xtitle("Kurtosis") ytitle("CIR ") ylabel(24(1)27) 
graph export "$path\Graphs_Tables\Figure6_b.png", replace
graph export "$path\Graphs_Tables\Figure6_b.eps", replace



